﻿Public Class UserInfo

    Public Kod As Integer
    Public Ad, Soyad As String
    Public Birim As Integer = -1
    Public Durum As KullaniciDurumu
    Public Uygulama As String
    Public Yetkiler As New List(Of Yetki)

    Sub SetYetki(Text As String)
        If Text = "" Then Return
        For Each Yetki As String In Text.Split(",")
            Dim Items = Yetki.Split(".")
            If Items.First = Uygulama Then Yetkiler.Add(New Yetki(Items(1)))
        Next
    End Sub

    Public Enum KullaniciDurumu
        OK
        InvalidPassword
        MustChangePassword
    End Enum

    ReadOnly Property [Operator]() As Boolean
        Get
            Return (From y In Yetkiler Where y.Tur = "opr").Any
        End Get
    End Property

    ReadOnly Property [Yonetici]() As Boolean
        Get
            Return (From y In Yetkiler Where y.Tur = "mgr").Any
        End Get
    End Property

    ReadOnly Property OprBirim As Integer
        Get
            Return (From y In Yetkiler Where y.Tur = "opr").FirstOrDefault.Birim
        End Get
    End Property

    ReadOnly Property MgrBirim As Integer
        Get
            Return (From y In Yetkiler Where y.Tur = "mgr").FirstOrDefault.Birim
        End Get
    End Property

    ReadOnly Property TBirim As Integer
        Get
            If Yonetici Then Return MgrBirim
            If [Operator] Then Return OprBirim
            Return -1
        End Get
    End Property

End Class

Public Class Yetki

    Public Tur As String
    Public Birim As Integer

    Sub New(Def As String)
        Dim Pos = InStr(Def, "(")
        Tur = Mid(Def, 1, Pos - 1)
        Birim = Val(Mid(Def, Pos + 1))
    End Sub

End Class